#include <func.h>

int main(int argc, char* argv[])
{
    if(argc != 2)
        error(1, 0, "Usage: %s file", argv[0]);

    int fd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, 0666);
    if(fd == -1)
        error(1, errno, "open %s failed", argv[1]);

    if(ftruncate(fd, 40959) == -1)
        error(1, errno, "ftruncate");

    printf("lseek = %ld\n", lseek(fd, 0, SEEK_END));
    if(lseek(fd, 0, SEEK_END) == -1)
        error(1, errno, "lseek");
    write(fd, "Hello world", 11);

    struct stat statbuf;
    fstat(fd, &statbuf);
    printf("st_blocks = %ld\n", statbuf.st_blocks); // 值应该为 8

    close(fd);
    return 0;
}

